home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++
- Subject: Re: mutual data structures
- Date: 23 Mar 1996 21:14:02 GMT
- Organization: Pipeline USA
- Message-ID: <4j1piq$63d@news1.h1.usa.pipeline.com>
- References: <4j1mu1$fas@baskerville.CS.Arizona.EDU>
- NNTP-Posting-Host: 38.8.60.5
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Mar 23, 1996 13:28:49 in article <mutual data structures>,
- 'kdb@CS.Arizona.EDU (Koen De Bosschere)' wrote:
-
-
- >I am trying to create a data structure consisting of
- >two linked lists, with nodes pointing at each other
- >between the two lists.
- >
- >The problem is that in order to create typed pointers, I
- >need the definition of the class, and no matter how I reorder
- >the class definitions, there will always be an undefined
- >class at some point.
- >
- >class node1 {
- >....
- >node2 *pointer; // node2 undefined at this point
- >....
- >};
- >
- >class node2 {
- >....
- >node1 *pointer;
- >....
- >};
- >
- >I was wondering whether there is an elegant solution
- >for this kind of problem. This kind of data structure
- >cannot be so unusual, so other people must have faced
- >this problem before.
- >
- Well, I don't know about elegancy, but the standard
- solution is called "forward declaration". Stick the following line
- at the top of the file whose code you have included in this post:
-
- class node2;
-
- --
-
- Pete Grant
- Kalevi, Inc.
- Sofware Engineering
-